@extends('home.layout.base')
<link rel="stylesheet" href="{{URL::asset('./css/hrmy/public.css')}}">
<link rel="stylesheet" href="{{URL::asset('./css/hrmy/safe_pass.css')}}">
<style type="text/css">
    .userDetails .errInput {
        margin-bottom: 20px;
    }

    .userDetails .errInput .el-form-item__error {
        top: 95%;
    }
</style>
@section('content')
<div class="mainHrContent" id="hrSafe">
    <div class="storelistTitle" id="storelistTitle" v-cloak>
        <span class="storelistTitle_left">
            <span>
                <img src="{{URL::asset('./img/icon/home.png')}}">
            </span>
            <span><a href="{{route('home.index.index') }}">首页</a> >
                <a href="{{route('home.hrmy.hrIndex') }}">用户中心</a>
                > 安全中心
            </span>
        </span>
        <span class="storelistTitle_right">
            <span>找不到合适的供应商？发个需求试试？</span>
            <button @click=" window.location.href = '{{ route('home.demand.demandAdd') }}'">免费发布需求</button>
        </span>
    </div>
    <div class="hrContent">
        @include('home.hrmy.menu')
        <div class="basicInfo" id="hrSafes" v-cloak>
            <div class="basicInfo_title">
                <span></span>
                安全中心 > 密码修改
            </div>
            <div class="userDetails">
                <el-form :model="form" :rules="rules" ref="ruleForm">
                    <p style=" font-weight: 540;text-shadow: 0px 0px 0px #000;">
                        <span class="details_title">已验证手机：</span>
                        @{{mobile}}
                    </p>
                    <el-form-item prop="newPass">
                        <p>
                            <span class="details_title">新密码：</span>
                            <el-input v-model="form.password"></el-input>
                        </p>
                    </el-form-item>
                    <el-form-item prop="verifyPass">
                        <p>
                            <span class="details_title">确认密码：</span>
                            <el-input v-model="form.verifyPass"></el-input>
                        </p>
                    </el-form-item>
                    <el-form-item prop="captcha" :rules="captchaRule" class="errInput">
                        <span class="details_title">图形验证码：</span>
                        <el-input style="width:140px;" v-model="form.captcha"></el-input>
                        <img class="codeImg" style="width:130px;height: 40px;" @click="captchar" :src="captchaLink">
                        <span style="color: #888;font-size: 12px;"><i class="fa fa-question-circle-o"></i> 看不清，点击验证码换一张</span>
                    </el-form-item>
                    <el-form-item prop="code">
                        <p>
                            <span class="details_title">手机验证码：</span>
                            <el-input style="width:140px;" v-model="form.code"></el-input>
                            <a class="getCode" @click="getCode">获取验证码
                                <span v-if="codeBo">
                                    @{{'（'+codeTime+'）'}}
                                </span>
                            </a>
                        </p>
                    </el-form-item>
                </el-form>
                <button @click="submitForm('ruleForm')">保存修改</button>
            </div>
        </div>
    </div>
</div>
@endsection
@section('compontentScipts')
<script>
    $(() => {
        let hrSafe = new Vue({
            el: '#hrSafes',
            data: () => {
                return {
                    captchaLink: '',
                    form: {
                        password: '',
                        verifyPass: '',
                        code: "",
                        newPass: '',
                        captcha: ''
                    },
                    mobile: '',
                    captchaRule: [{
                        required: true,
                        message: '图形验证码不能为空',
                        trigger: 'blur'
                    }],
                    rules: {
                        password: [{
                            required: true,
                            message: "密码不得为空",
                            trigger: 'blur'
                        }],
                        verifyPass: [{
                            required: true,
                            message: "密码不得为空",
                            trigger: 'blur'
                        }],
                        code: [{
                            required: true,
                            message: '验证码不能为空',
                            trigger: 'blur'
                        }],
                    },
                    codeBo: false,
                    codeTime: 60,
                }
            },
            created() {
                this.captchar();
                this.mobile = JSON.parse(sessionStorage.getItem("HRuserDetails")).mobile
            },
            mounted() {},
            methods: {
                submitForm(formName) {
                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                            if (this.form.password == this.form.verifyPass) {
                                apiAjax("{{ route('home.user.userChangePwdApi') }}", 'post', {
                                    mobile: this.mobile,
                                    password: this.form.password,
                                    confirmc_pwd: this.form.verifyPass,
                                    code: this.form.code,
                                }, (res) => {
                                    if (res.code == 0) {
                                        this.$message({
                                            message: res.msg,
                                            type: 'success'
                                        });
                                        window.location.href = "{{ route('home.login.login') }}";
                                    } else {
                                        this.$message({
                                            message: res.msg,
                                            type: 'warning'
                                        });
                                    }
                                }, (erro) => {

                                });

                            } else {
                                this.$message({
                                    message: "两次密码不一致",
                                    type: 'warning'
                                });
                            }
                        } else {
                            console.log('error submit!!');
                            return false;
                        }
                    });
                },
                getCode() {
                    if (this.codeTime == 60) {
                        apiAjax("{{ route('home.phone.getSMS') }}", 'post', {
                            captcha: this.form.captcha,
                            phone: this.mobile
                        }, (res) => {
                            if (res.code == 0) {
                                this.$message({
                                    message: "验证码已发送至您的手机",
                                    type: 'success'
                                });
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: 'warning'
                                });
                            }
                        });
                    }

                },
                //图形验证码
                captchar() {
                    let that = this;
                    $.get("{{ route('admin.auth.captcha') }}", function(res) {
                        that.captchaLink = res.data;
                    }, 'JSON ');
                },
            }
        })
    })
</script>
@endsection